﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using Model.Models;

namespace EmpresaWeb.Controllers
{
    public class SegmentoController : Controller
    {
        private GerenciadorSegmento gSegmento;
        private GerenciadorEmpresa gEmpresa;
       
        public SegmentoController()
        {
            gSegmento = new GerenciadorSegmento();
            gEmpresa = new GerenciadorEmpresa();
        }
        //
        // GET: /Segmento/

        public ViewResult Index()
        {
            return View(gSegmento.ObterTodos());
        }

        public ActionResult Create()
        {
            ViewBag.Id_Empresa = new SelectList(gEmpresa.ObterTodos(), "Id_Empresa", "Nome");
            return View();
        }

        //
        // GET: /Segmento/Details/5

        public ViewResult Details(int id)
        {
            Segmento segmento = gSegmento.Obter(id);
            return View(segmento);
        }

        //
        // GET: /Segmento/Create

        
        //
        // POST: /Segmento/Create

        [HttpPost]
        public ActionResult Create(Segmento segmentoModel)
        {
            if (ModelState.IsValid)
            {
                gSegmento.Inserir(segmentoModel);
                return RedirectToAction("Index");
            }

            return View(segmentoModel);
        }

        //
        // GET: /Segmento/Edit/5

        public ActionResult Edit(int id)
        {

            Segmento segmento = gSegmento.Obter(id);
            return View(segmento);
        }

        //
        // POST: /Segmento/Edit/5

        [HttpPost]
        public ActionResult Edit(Segmento segmentoModel)
        {
            if (ModelState.IsValid)
            {
                gSegmento.Editar(segmentoModel);
                return RedirectToAction("Index");
            }
            return View(segmentoModel);
        }

        //
        // GET: /Segmento/Delete/5

        public ActionResult Delete(int id)
        {
            Segmento autoModel = gSegmento.Obter(id);
            return View(autoModel);
        }

        //
        // POST: /Segmento/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            gSegmento.Remover(id);
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }
}
